<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let ary = [1, 2, 3, 1, 2, 1, 2, 3, 2, 1, 2, 3]
        ary.sort((a, b) => a - b)
        let str = ary.join('@') + '@'
        let reg = /(\d+@)\1*/g;
        ary = []
        str.replace(reg, (n, m) => {
            m = Number(m.slice(0, m.length - 1))
            ary.push(m)
        })
        console.log(ary);
    </script>
</body>

</html>